package com.pt.iwebshop.web;


import com.pt.iwebshop.model.EbNews;
import com.pt.iwebshop.model.EbProductCategory;
import com.pt.iwebshop.service.EbNewsService;
import com.pt.iwebshop.service.EbProductCategorySercie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/news")
public class NewsController {
	@Autowired
	private EbNewsService ebNewsService;
	@Autowired
	EbProductCategorySercie ebProductCategorySercie;

	@RequestMapping("/detail")
	public String detail(Model model, Integer enId){
		//1.调用service查询该新闻的详细信息
		EbNews ebNewsDetail=ebNewsService.detail(enId);
		//1.1.调用service层查询商品分类信息
		Map<String, List<EbProductCategory>> categoryMap =ebProductCategorySercie.selectBigAndSmallCate();
		//2.把数据绑定到model
		model.addAttribute("detail",ebNewsDetail);
		//2.1 将商品分类进行绑定
		model.addAttribute("categotyMap",categoryMap);
		//3.返回视图名称
		return "news-view";
	}
}
